﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using YiSha.Business.YiDongYuan;
using YiSha.Entity.YiDongYuan;
using YiSha.Util.Extension;

namespace YiSha.Admin.Web.Controllers
{
    public class MechanicsController : Controller
    {
        private MechanicsBLL mechanicsBLL = new MechanicsBLL();

        public IActionResult QrCode(string id)
        {
            MechanicsEntity model = null;
            string code = Request.Query["code"];
            if (!code.IsNullOrEmpty())
            {
                model = mechanicsBLL.GetEntity(code).Result.Data;
            }
            else
            {
                if (id.ParseToLong() != 0)
                    model = mechanicsBLL.GetEntity(id.ParseToLong()).Result.Data;
                else
                    model = mechanicsBLL.GetEntity(id).Result.Data;
            }
            if (model != null)
            {
                var detection = new DetectionTaskBLL().GetLastEntityByCode(model.HuanBaoCode).Result.Data;
                if (detection != null)
                {
                    ViewBag.task = detection;
                    DetectionInfoEntity check = new DetectionInfoBLL().GetEntity(detection.DetectionInfoId.Value).Result.Data;
                    ViewBag.check = check;
                    ViewBag.test = new DetectionResultBLL().GetEntity(check.ResultDataId.Value).Result.Data;
                }
            }
            ViewBag.Mechanics = model;
            return View();
        }
    }
}
